# -*- coding: UTF-8 -*-
"""
@File    ：第五周-第三节-作业(协程).py
@Author  ：Super
@Date    ：2021/1/17
@Desc    ：
"""
import asyncio


class Response:
    status_code = 200


async def request_test(index):
    print(f"当前请求序号: {index}")
    response = Response()
    await asyncio.sleep(1)
    print(f"request 序号: {index}, response 相应状态码: {response.status_code}")
    return response.status_code


def avg():
    total = 0
    len = 0
    while True:
        total += yield
        len += 1
        print("total = ", total, "n = ", len)
        print("mean = ", total / len)


# x = avg()
# next(x)  # 预激活，使其停留在第一个yield位置
# while True:
#     print("Please input number...")
#     x.send(float(input()))

loop = asyncio.get_event_loop()  # 获取消息队列
task_list = []
for i in range(10):
    task_list.append(request_test(i))

# 循环访问事件完成异步消息维护
loop.run_until_complete(asyncio.wait(task_list))

loop.close()  # 关闭事件循环
